﻿using Common.AspNetCore;
using Common.EF;
using StatsData.Data.Entity;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace StatsData.Api.Repository
{
    public class StatsDataRepository : CoreRepository
    {
        private readonly ICommonModelRepository repository;

        public StatsDataRepository(IServiceProvider provider, ICommonModelRepository repository)
            : base(provider)
        {
            this.repository = repository;
        }

        public ICommonRepository CommonRepository
        {
            get { return this.Repository; }
        }

        public ICommonModelRepository CommonModelRepository
        {
            get { return this.repository; }
        }

        public async Task CommitChangesByCommonAsync(Action func)
        {
            await CommitChangesAsync(func);
        }

        public async Task<bool> AddOrUpdateManuSourceHourEfficiencyAsync(List<t_manu_source_hour_efficiency> addEnities, List<t_manu_source_hour_efficiency> updateEntities)
        {
            await CommitChangesAsync(() =>
            {
                this.Repository.AddEntities<t_manu_source_hour_efficiency>(addEnities);
                this.Repository.UpdateEntities<t_manu_source_hour_efficiency>(updateEntities);
            });

            return true;
        }
    
        public async Task<List<t_manu_source_hour_efficiency>> GetManuSourceHourEfficiencyAsync(List<string> lineIds, string orgId, DateTime startTime, DateTime endTime)
        {
            return await this.Repository.GetEntitiesAsync<t_manu_source_hour_efficiency>(t => t.org_id == orgId && t.curr_date >= startTime && t.curr_date <= endTime && lineIds.Contains(t.line_id));
        }
    }
}
